package com.binance.mbxgateway.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.binance.master.models.APIRequest;
import com.binance.master.models.APIResponse;
import com.binance.mbxgateway.api.IOrderApi;
import com.binance.mbxgateway.vo.request.order.DeleteAllOrderRequest;
import com.binance.mbxgateway.vo.request.order.DeleteOrderRequest;
import com.binance.mbxgateway.vo.request.order.DeleteOrderResponse;
import com.binance.mbxgateway.vo.request.order.PlaceOrderRequest;
import com.binance.mbxgateway.vo.response.order.PlaceOrderResponse;
import com.binance.mbxgateway.web.service.IOrderService;

@RestController
public class OrderController implements IOrderApi {

    @Autowired
    private IOrderService orderService;

    @Override
    public APIResponse<PlaceOrderResponse> placeOrder(@RequestBody @Validated APIRequest<PlaceOrderRequest> request)
            throws Exception {
        return APIResponse.getOKJsonResult(this.orderService.placeOrder(request.getBody()));
    }

    @Override
    public APIResponse<DeleteOrderResponse> deleteOrder(@RequestBody @Validated APIRequest<DeleteOrderRequest> request)
            throws Exception {
        return APIResponse.getOKJsonResult(this.orderService.deleteOrder(request.getBody()));
    }

    @Override
    public APIResponse<DeleteOrderResponse> deleteAllOrder(@RequestBody @Validated APIRequest<DeleteAllOrderRequest> request)
            throws Exception {
        return APIResponse.getOKJsonResult(this.orderService.deleteAllOrder(request.getBody()));
    }

}
